package dao

import (
	"context"
	"gorm.io/gorm"
	"listenboos-common/db"
	"listenboos-common/db/gorms"
	"ucenter/model"
)

type UserPaidAlbumDao struct {
	conn *gorms.GormConn
}

func NewUserPaidAlbumDao(db *db.ListenDB) *UserPaidAlbumDao {
	return &UserPaidAlbumDao{
		conn: gorms.New(db.Conn),
	}
}
func (u *UserPaidAlbumDao) FindPaidAlbum(ctx context.Context, userId int64, albumId int64) (paidAlbum *model.UserPaidAlbum, err error) {
	session := u.conn.Session(ctx)
	err = session.Model(&model.UserPaidAlbum{}).Where("user_id = ? and album_id = ?", userId, albumId).First(&paidAlbum).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		return nil, err
	}
	return paidAlbum, nil

}
